package com.example.spark.rdd;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

public class SparkRDDExample_2 {
    public static void main(String[] args) {

        //创建配置对象
        SparkConf conf = new SparkConf();
        conf.setMaster("local");
        conf.setAppName("spark_demo");

        //创建SparkContext
        JavaSparkContext jsc = new JavaSparkContext(conf);
        //编写逻辑代码
         //从文件获取内容
        JavaRDD<String> rdd = jsc.textFile("input/1.txt");
        List<String> collect = rdd.collect();
        collect.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        System.out.println("===========================");
        collect.forEach(System.out::println);


        //关闭,回收资源
        jsc.stop();


    }



}
